package com.hpq.common.domain.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * ws前端请求类型枚举
 */
@AllArgsConstructor
@Getter
public enum YesOrNoEnum {
    YES(1,"是"),
    NO(0,"否"),
    ;
    private final Integer status;
    private final String desc;
    private static  Map<Integer, YesOrNoEnum> cache;
    static{
        cache = Arrays.stream(YesOrNoEnum.values()).collect(Collectors.toMap(YesOrNoEnum::getStatus, Function.identity()));
    }
    public static YesOrNoEnum of(Integer status){
        return cache.get(status);
    }
    public static Integer toStatus(Boolean bool){
        return bool ? YES.getStatus() : NO.getStatus();
    }
}
